$(function() {
    $('[data-bs-toggle="tooltip"]').tooltip()
});

jQuery(document).ready(function() {
    jQuery('.scrollbar-inner').scrollbar();
});

$(document).ready(function() {
    var toggle_sidebar = false,
        toggle_topbar = false,
        nav_open = 0,
        topbar_open = 0;

    if (!toggle_sidebar) {
        $toggle = $('.sidenav-toggler');

        $toggle.click(function() {
            if (nav_open == 1) {
                $('html').removeClass('nav_open');
                $toggle.removeClass('toggled');
                nav_open = 0;
            } else {
                $('html').addClass('nav_open');
                $toggle.addClass('toggled');
                nav_open = 1;
            }
        });
        toggle_sidebar = true;
    }

    if (!toggle_topbar) {
        $topbar = $('.topbar-toggler');

        $topbar.click(function() {
            if (topbar_open == 1) {
                $('html').removeClass('topbar_open');
                $topbar.removeClass('toggled');
                topbar_open = 0;
            } else {
                $('html').addClass('topbar_open');
                $topbar.addClass('toggled');
                topbar_open = 1;
            }
        });
        toggle_topbar = true;
    }

    //select all
    $('[data-select="checkbox"]').change(function() {
        $target = $(this).attr('data-target');
        $($target).prop('checked', $(this).prop("checked"));
    })

    var mobileCheck = isMobile();
    if (mobileCheck) {
        phoneRender();
    }
});

function phoneRender() {
    $(".phone-scoller").text("右滑查看更多");
    $("#version").hide();
    var alertClose = localStorage.getItem('alertClose') || 1;
    if (alertClose == 1) {
        var orient = checkOrient();
        if (orient) {
            $(".phone-alert").html('<div class="alert alert-warning"><i class="icon bx bxs-volume-full"></i>检测到手机访问，建议横屏或电脑访问系统<i class="close bx bx-x" onclick="closePhoneAlert();"></i></div>');
            $(".phone-table-alert").html('<div class="alert alert-dark" style="margin-top:15px;"><i class="icon bx bxs-volume-full"></i>上方右滑可查看完整表格<i class="close bx bx-x" onclick="closePhoneAlert();"></i></div>');
        }
    } else {
        $(".phone-alert").hide();
        $(".phone-table-alert").hide();
    }
}

function closePhoneAlert() {
    localStorage.setItem("alertClose",2);
    $(".phone-alert").hide();
    $(".phone-table-alert").hide();
}

function getWechatService() {
    $("#service_qrcode").attr("src", "https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/links/20230105/5e92573de9e3230db42245c7b9b68e01.jpg");
    $("#service_text").text("天天外链客服");
    $("#service_time").text("工作日(9:00-18:00)");
    $("#service_describe").text("您在使用过程中遇到任何问题，请联系微信客服为您处理与解答。");
    $('#serviceModal').modal('toggle');
}


function checkOrient() {
    if(window.orientation === 90){
        return false;// 竖屏
    }
    if(window.orientation === 0){
        return true;//横屏
    }
}

function isMobile(){
    var userAgentInfo = navigator.userAgent;
    var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    var mobile_flag = false;
    //根据userAgent判断是否是手机
    for (var v = 0; v < mobileAgents.length; v++) {
        if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
            mobile_flag = true;
            break;
        }
    }
    var screen_width = window.screen.width;
    var screen_height = window.screen.height;

    //根据屏幕分辨率判断是否是手机
    if (screen_width > 325 && screen_height < 750) {
        mobile_flag = true;
    }
    return mobile_flag;
}
